package org.example.core;

import com.sun.net.httpserver.HttpExchange;

import java.util.Map;

/**
 * 请求上下文 - 封装请求相关信息
 */
public class RequestContext {
    private final HttpExchange exchange;
    private final Map<String, String> pathParams;
    private final Map<String, String> queryParams;
    private final String requestBody;

    public RequestContext(HttpExchange exchange,
                          Map<String, String> pathParams,
                          Map<String, String> queryParams,
                          String requestBody) {
        this.exchange = exchange;
        this.pathParams = pathParams;
        this.queryParams = queryParams;
        this.requestBody = requestBody;
    }

    // Getter methods
    public HttpExchange getExchange() { return exchange; }
    public Map<String, String> getPathParams() { return pathParams; }
    public Map<String, String> getQueryParams() { return queryParams; }
    public String getRequestBody() { return requestBody; }

    /**
     * 获取路径参数
     */
    public String getPathParam(String name) {
        return pathParams.get(name);
    }

    /**
     * 获取查询参数
     */
    public String getQueryParam(String name) {
        return queryParams.get(name);
    }
}